package belf.migrate.api.type;

import belf.migrate.api.common.DatabaseIdentifier;

import java.util.List;

public enum ObjectCompatibleType {
    ORACLE(DatabaseIdentifier.ORACLE, List.of(DbObjectType.FUNCTION, DbObjectType.PROCEDURE, DbObjectType.TABLE, DbObjectType.TRIGGER, DbObjectType.TYPE, DbObjectType.VIEW)),
    MYSQL(DatabaseIdentifier.MYSQL, List.of(DbObjectType.FUNCTION, DbObjectType.PROCEDURE, DbObjectType.TABLE, DbObjectType.TRIGGER, DbObjectType.VIEW)),
    DAMENG(DatabaseIdentifier.DAMENG, List.of(DbObjectType.FUNCTION, DbObjectType.PROCEDURE, DbObjectType.TABLE, DbObjectType.TRIGGER, DbObjectType.VIEW));


    private String dbType;

    private List<DbObjectType> objectTypeList;


    ObjectCompatibleType(String dbType, List<DbObjectType> objectTypeList) {
        this.objectTypeList = objectTypeList;
        this.dbType = dbType;
    }

    public List<DbObjectType> getObjectType() {
        return objectTypeList;
    }

    public void setObjectType(List<DbObjectType> objectType) {
        this.objectTypeList = objectType;
    }

    public String getDbType() {
        return dbType;
    }

    public void setDbType(String dbType) {
        this.dbType = dbType;
    }

    public static boolean notCompatibleType(String sourceDbType, String sinkDbType, DbObjectType dbObjectType) {
        boolean source = false;
        boolean sink = false;
        for (ObjectCompatibleType objectCompatibleType : ObjectCompatibleType.values()) {
            if (objectCompatibleType.getDbType().equals(sourceDbType) && objectCompatibleType.getObjectType().contains(dbObjectType)) {
                source = true;
            }
            if (objectCompatibleType.getDbType().equals(sinkDbType) && objectCompatibleType.getObjectType().contains(dbObjectType)) {
                sink = true;
            }
        }
        return source && !sink;
    }


}
